package com.dingli.service.impl;

import com.dingli.framework.entity.Enterprise;
import com.dingli.framework.entity.Member;
import com.dingli.framework.mapper.EnterpriseMapper;
import com.dingli.framework.util.Response;
import com.dingli.service.IEnterpriseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EnterpriseService implements IEnterpriseService{

    @Autowired
    private EnterpriseMapper enterpriseMapper;


    @Override
    public Response<PageInfo<Enterprise>> Eslist(String search, Integer pageNum, Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 5;
        }
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<Enterprise> info = new PageInfo<>(enterpriseMapper.Eslist(search));
        return new Response<>(200, "success", info);
    }


    @Override
    public Response<Long> Eseinsert(Enterprise enterprise) {
        int count = enterpriseMapper.Eseinsert(enterprise);
        if (count > 0) {
            return new Response(200, "success", enterprise.getEseId());
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Enterprise> EseselectById(Long eseId) {
        return new Response(200, "success", enterpriseMapper.EseselectById(eseId));
    }

    @Override
    public Response<Object> EseupdateById(Enterprise enterprise) {
        int count = enterpriseMapper.EseupdateById(enterprise);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> EsedeleteById(Long eseId) {
        int count = enterpriseMapper.EsedeleteById(eseId);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> EseupdateState(String eseId) {
        int count = enterpriseMapper.EseupdateState(eseId);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> Eseupdate(String eseId) {
        int count = enterpriseMapper.Eseupdate(eseId);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<List<Enterprise>> EseselectState(String eseState) {
        List<Enterprise> enterprises = enterpriseMapper.EseselectState(eseState);
        return new Response<>(200,"success", enterpriseMapper.EseselectState(eseState));
    }

    @Override
    public Response<List<Enterprise>> EseselectState1(String eseState) {
        List<Enterprise> enterprises = enterpriseMapper.EseselectState1(eseState);
        return new Response<>(200,"success", enterpriseMapper.EseselectState1(eseState));
    }

    @Override
    public Response<List<Enterprise>> EseAll(String eseId) {
        return new Response<>(200,"success", enterpriseMapper.EseAll(eseId));
    }
}
